  /*
  格式化树形
  datas需要过滤的数据
  最外层节点的parentId
  defaultProp为树形数据的默认配置
  */

 const getListData = function getListData(datas,bigPid,defaultProp) {
    if(!defaultProp){
      defaultProp={
          label: 'deptName',
          id:'id',
          parentId:'parentId'
      }
    }  
    let dataArray = []
    datas.forEach(function(data) {
      let pid = data[defaultProp.parentId]
      if (pid == bigPid) {
        let objTemp = {}
        for(var pl in data){ //数组对象遍历
            objTemp[pl] = data[pl]
        }
        dataArray.push(objTemp)
      }
    })
    return data2treeDG(datas, dataArray, defaultProp)
  }
  function  data2treeDG(datas, dataArray, defaultProp) {
      for (let j = 0; j < dataArray.length; j++) {
        let dataArrayIndex = dataArray[j]
        let childrenArray = []
        let Id = dataArrayIndex[defaultProp.id]
        for (let i = 0; i < datas.length; i++) {
          let data = datas[i]
          let pid = data[defaultProp.parentId]
          if (pid == Id) {
            //判断是否为儿子节点
            let objTemp = {}
            for(var pl in data){ //数组对象遍历
                objTemp[pl] = data[pl]
            }
            childrenArray.push(objTemp)
          }
        }
        dataArrayIndex.children = childrenArray
        if (childrenArray.length > 0) {
          //有儿子节点则递归
          data2treeDG(datas, childrenArray, defaultProp)
        }else if(childrenArray.length <1){
          dataArrayIndex.children = undefined;
        }
      }
      return dataArray
    }
    export default getListData;
